/*
 * @Description:
 * @Version: 2.0
 * @Autor: zhangjx
 * @Date: 2023-03-31 11:58:58
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-03-13 12:40:51
 */
export default defineComponent({
	props: {
		modelName: {
			type: String,
		},
		fileLabel: {
			type: String,
		},
		placeholder: {
			type: String,
		},
		dicData: {
			type: Array,
			default: () => [],
		},
	},
	setup(props, { slots, attrs, emit }) {
		const onChange = (valueKey: any) => {
			const getLabel = (value) => {
				const keys = Array.isArray(value) ? value : [value]
				const labelName = props.dicData.filter((item: any) => keys.includes(item.value)).map((item: any) => item.label)
				return labelName
			}
			if (props.fileLabel) {
				const data = getLabel(valueKey)
				emit('update:modelName', data?.join(','))
			}
		}
		const handleClear = () => {
			emit('update:modelName', undefined)
		}

		return () => {
			return <el-select v-slots={slots} placeholder={props.placeholder} onChange={(e) => onChange(e)} onClear={handleClear}></el-select>
		}
	},
})
